package com.prs.crm.service.sys.impl;

import java.util.Collection;

import com.prs.crm.dao.sys.ModuleDao;
import com.prs.crm.dao.sys.UIResourceDao;
import com.prs.crm.domain.sys.Module;
import com.prs.crm.domain.sys.UIResource;
import com.prs.crm.service.impl.BaseServiceImpl;
import com.prs.crm.service.sys.ModuleService;

public class ModuleServiceImpl extends BaseServiceImpl<Module,ModuleDao> implements ModuleService{

	private UIResourceDao uiResourceDao;
	
	public void setUiResourceDao(UIResourceDao uiResourceDao) {
		this.uiResourceDao = uiResourceDao;
	}

	public UIResourceDao getUiResourceDao() {
		return uiResourceDao;
	}
	
	public void setHome(UIResource resource)
	{
		uiResourceDao.setHome(resource);
	}
	
	public Collection<Module> getAllModule()
	{
		return this.getDao().getAllModule();
	}
	
	public 	void saveResource(Module module,UIResource resource)
	{
		if (module.getResources()==null 
				|| module.getResources().size()<1)
			resource.setHome(true);
		module.addResource(resource);
		this.save(module);
	}

	public void removeResource(UIResource resource)
	{
		Module module = resource.getModule();
		module.getResources().remove(resource);
		this.save(module);
	}

	@Override
	public UIResource getUIResource(String url) {
		// TODO Auto-generated method stub
		return uiResourceDao.getUIResource(url);
	}
}
